package com.youpai.platform.common.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @time: 2021/12/10 7:46 下午
 * @author: welles
 * @description: 邮件发送工具类
 */
@Component
public class SendEmailUtil {

    @Resource
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String fromUserName;

    /**
     * 发送纯文本邮件
     *
     * @param toEmail 接收方的邮件
     * @param subject 邮件主题
     * @param text    文本内容
     */
    public void sendMail(String toEmail, String subject, String text) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(fromUserName);
        message.setTo(toEmail);
        message.setSubject(subject);
        message.setText(text);
        javaMailSender.send(message);
    }
}
